import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        int k = in.nextInt();
        Deque<Character> deque = new LinkedList<>();
        for (char c : str.toCharArray()) {
            if (deque.size() == 0 || c != deque.peekLast()) {
                deque.offer(c);
            } else {
                deque.offer(c);
                int count = 0;
                Deque<Character> deque2 = new LinkedList<>();
                while (deque.size() > 0 && deque.peekLast() == c) {
                    count++;
                    deque2.offer(deque.pollLast());
                }
                if (count < k) {
                    while (deque2.size() > 0) {
                        deque.offer(deque2.pollLast());
                    }
                }
            }
        }
        StringBuilder ret = new StringBuilder();
        while (deque.size() > 0) {
            ret.append(deque.pollFirst());
        }
        System.out.println(ret.toString());
    }
}
